beginoutdoorscript;

variables;
short safety = 0;
short pc_counter;

body;

beginstate 0; //INIT_STATE
break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
	//get rid of the ship
	if((get_flag(53,1) == 1) && (get_terrain(31,9) == 491)) {
		set_terrain(31,9,0);
		set_terrain(32,9,0);
		}
break;

beginstate 10; //sand runes
	if(get_flag(53,5) == 1)
		end();
	if(has_item(445) == 0)
		end();
	
	reset_dialog();
	add_dialog_str(0,"The key you got from the crazy hermit starts vibrating in your pack, and you notice something small and metallic glinting in the sand. You pick it up.",0);
	run_dialog(1);
	
	reward_give(271); //ring of health
	
	set_flag(53,5,1);
break;

beginstate 20; //approaching the island
	if(get_flag(53,0) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"Stopping occasionally to plug up new leaks in the boat, you paddle onward. To the south, you can see another island, one with a large column of smoke rising from it.",0);
	add_dialog_str(1,"Unsurprisingly, you can see another Darkside ship anchored not too far off the coast. As far as you can see, it's the only one around.",0);
	add_dialog_str(2,"Fortunately, you know enough about these islands to know that Copperpeak isn't that much farther away. And if you wanted, you could just avoid this island entirely.",0);
	run_dialog(1);
	set_flag(53,0,1);
break;

beginstate 25; //don't charge at the ships
	if(get_flag(53,1) != 0)
		end();
	message_dialog("Charging directly at the Loyalist ships, while perhaps brave in some circles, is probably suicidal.","You turn back.");
	block_entry(1);
break;

beginstate 30; //noise from up ahead
	if(get_flag(53,3) > 0)
		end();
	reset_dialog();
	add_dialog_str(0,"You're not very surprised to hear the sounds of fighting up ahead. At least someone around here is putting up a fight...",0);
	run_dialog(1);
	set_flag(53,3,1);
break;

beginstate 31; //Darkside raiding party
	if(get_flag(53,3) == 3) {
		message_dialog("The farmhouses are deserted. The Loyalists must've finished pillaging them.","");
		end();
		}
	else if(get_flag(53,3) == 4) {
		message_dialog("You find the farmers hard at work cleaning up the area. You make small talk for a little while, but don't learn anything new.","");
		end();
		}
	if(get_flag(53,3) > 1)
		end();
		
	//armor check
	pc_counter = 0;
	while((pc_counter < 4) && (safety == 0)) {
		if((char_ok(pc_counter) == 1) && (item_type_in_slot(pc_counter,0) != 447))
			safety = 1; //not safe if armor isn't equipped
		pc_counter = pc_counter + 1;
		}
	
	reset_dialog();
	add_dialog_str(0,"As you burst into the clearing, you stumble upon what appears to be a group of Loyalists pillaging some farmhouses.",0);
	add_dialog_str(1,"One particularly large Loyalist has cornered a group of farmers, probably just keeping them from escaping. The farmers are understandably distraught.",0);
	if(safety == 0) {
		add_dialog_str(2,"Of course, your arrival causes rather a lot of confusion. The Loyalists don't recognize you, but you're wearing their armor. The farmers just see you as more Loyalists.",0);
		add_dialog_str(3,"Most of the Loyalists look to the largest of the group, who seems to be sizing you up. After the longest thirty seconds of your life, he points at you and grunts.",0);
		add_dialog_str(5,"Oh well... it was worth a shot.",0);
		}
	else 
		add_dialog_str(2,"Of course, the scene changes dramatically when you arrive. The Loyalists freeze when they notice you, and look to the larger one. He grunts, and points at you.",0);
	add_dialog_str(4,"You don't have a chance to react before they charge, weapons drawn. The farmers take this opportunity to run and hide in one of the buildings.",0);
	run_dialog(1);
	set_flag(53,3,2);
	
	//actually spawn the encounter
	create_out_spec_enc(0);
break;

beginstate 32; //set up the raiding party fight
	set_out_fight_town_loaded(9);
break;

beginstate 33; //fled the fight
	message_dialog("As you flee the fight, you turn back just in time to see the remaining Loyalists kill the farmers. Then they disperse.","Damn.");
	set_flag(53,3,3);
break;

beginstate 34; //won the fight
	reset_dialog();
	if(safety == 1)
		add_dialog_str(0,"As the last of the Loyalists falls, the farmers emerge from hiding. Some of them are visibly shaking. One of them steps forward and speaks.",0);
	else
		add_dialog_str(0,"As the last of the Loyalists falls, the farmers emerge from hiding. They're badly shaken, but at least they seem to have noticed that you're not Loyalists. One of them speaks up.",0);
	add_dialog_str(1,"_Thank you, thank you! You got here just in time... they were about to kill us because we wouldn't give up our possessions._",15);
	add_dialog_str(2,"The farmer pulls out a small silver bracelet and hands it over to you.",0);
	add_dialog_str(3,"_We don't have much, but we want you to have this. It's probably the most valuable thing we have between us, and I think it's magical. Either way, thank you for what you've done._",15);
	add_dialog_str(4,"The farmers check to make sure all of the Loyalists are gone, then start cleaning up the damage to their farms.",0);
	run_dialog(1);
	set_flag(53,3,4);
	award_party_xp(100,10);
	reward_give(446);
break;

beginstate 40; //first vision of Copperpeak
	if(get_flag(53,4) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"For the first time, you catch a glimpse of the island of Copperpeak, off to the northeast. You can see a few Darkside ships anchored around the island, unsurprisingly.",0);
	add_dialog_str(1,"Now you just need to slip past them, any soldiers on the shore, the soldiers surrounding the city, and the city walls themselves. Great.",0);
	run_dialog(1);
	set_flag(53,4,1);
break;